//
//  DBManager.m
//  WeChatMonitor
//
//  Created by TerryChe on 2016/11/24.
//  Copyright © 2016年 TerryChe. All rights reserved.
//

#import "DBManager.h"

@interface DBManager()

@property (nonatomic,strong) NSMutableDictionary* dicDB;

@end

@implementation DBManager

/**
 *  单例模式，
 *
 *  @return DBManager
 */
+(instancetype)sharedInstance{
    static DBManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
        sharedInstance.dicDB = [NSMutableDictionary dictionaryWithCapacity:10];
    });
    return sharedInstance;
}

/**
 *  初始化数据库
 *
 *  @param dbPath 数据库路径
 */
-(DBHelper*)getDBHelperBy:(NSString*)dbPath{
    DBHelper *helper = [_dicDB objectForKey:dbPath];
    
    if (helper == nil) {
        helper = [[DBHelper alloc] initWith:dbPath];
        [_dicDB setObject:helper forKey:dbPath];
    }
    
    return helper;
}

@end
